package com.example.android.wiktionary;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

/**
 * Class with a submenu
 *
 * @author CodingMonkeyz
 */
public class InGameMenu extends Activity {

	private static final int MENU = 0;

	private static final int NEW_MENU_ITEM = Menu.FIRST;
	private static final int QUIT_MENU_ITEM = NEW_MENU_ITEM + 1;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		menu.addSubMenu(MENU, NEW_MENU_ITEM, 0, "Restart game");
		menu.addSubMenu(MENU, QUIT_MENU_ITEM, 1, "Go to main page");
		return super.onCreateOptionsMenu(menu);
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case NEW_MENU_ITEM:
			showMsg("New");
			break;
		case QUIT_MENU_ITEM:
			//showMsg("Quit");
			Intent intent = new Intent(getApplicationContext(), MainMenu.class);
			InGameMenu.this.startActivity(intent);
			break;
		}
		return super.onOptionsItemSelected(item);
	}

	private void showMsg(String message) {
		Toast msg = Toast.makeText(InGameMenu.this, message, Toast.LENGTH_LONG);
		msg.setGravity(Gravity.CENTER, msg.getXOffset() / 2,
				msg.getYOffset() / 2);
		msg.show();
	}
}